Omplus.views.StatusNotificator = Omplus.base.extend(Omplus.views.Panel, {
    init:function () {
        for (var i in this.models) {
            if (!Omplus.globals.statusesReferences[this.omplusName])
                Omplus.globals.statusesReferences[this.omplusName] = [];
            Omplus.globals.statusesReferences[this.omplusName][this.models[i].omplusName] = true;
            this.references[this.models[i].omplusName] = this.models[i];
        }
    },
    models:[],
    references:{},
    index:0,
    omplusType: "StatusNotificator",
    setValue:function (newValue, model) {
        var array = new Array();
        if (Omplus.globals.getObject(model).getStatus() == Omplus.constants.status_ok) {
            if (Omplus.globals.getObject(this.references[model].successModel)) {
                var object = {
                    status:Omplus.constants.status_ok,
                    asset:this.references[model].successModel
                }
                array.push(object);
            }
        } else {
            var errors = Omplus.globals.getObject(model + ".errors").getValue();
            for (var i in errors) {
                if (Omplus.globals.getObject("Assets.list." + errors[i].name + ".localValue")) {
                    var object = {
                        status:Omplus.constants.status_error,
                        asset:"Assets.list." + errors[i].name + ".localValue"
                    }
                    array.push(object);
                }
            }
        }
        if (!array.length && (Omplus.globals.getObject(model).getStatus() == Omplus.constants.status_error || Omplus.globals.getObject(model).getStatus() == Omplus.constants.status_bad_request)) {
            console.log("aaa")
            array.push({
                status:Omplus.constants.status_error,
                asset:"Assets.list.err_process.localValue"
            });
        }
        for (var i in array) {
            var div = jQuery.extend(true, {}, $("<div><label></label></div>"));
            div.addClass(array[i].status).find("label").text(Omplus.globals.getObject(array[i].asset).getValue());
            div.css({display:"none"}).attr("id", this.omplusName + "_" + this.index);
            this.content.find(".layout").append(div);
            div.show("slide", {direction:"down"},300);
            setTimeout('Omplus.globals.getObject("' + this.omplusName + '").remove("#' + this.omplusName + "_" + this.index + '")', 3000);
            this.index++;
        }
    },
    remove:function (id) {
        $(id).fadeOut(300, function () {
            $(this).remove();
        });
    }
});

Omplus.globals.statusesReferences = {}
Omplus.globals.getStatusesReferences = function(model){
    for(var i in Omplus.globals.statusesReferences){
        if (Omplus.globals.statusesReferences[i][model]) return i;
    }
    return false;
}

Omplus.views.AlertsNotificator = Omplus.base.extend(Omplus.views.Panel, {
    omplusType: "AlertsNotificator",
    index:0,
    setValue:function (newValue) {
        for (var i in newValue.new_alerts) {
            var div = jQuery.extend(true, {}, $("<div><label></label></div>"));
            div.addClass("alert").find("label").text(Omplus.globals.getObject("Assets.list.text_for_alert" + newValue.new_alerts[i].code + ".localValue").getValue());
            div.css({display:"none"}).attr("id", this.omplusName + "_" + this.index);
            this.content.find(".layout").append(div);
            div.show("slide", {direction:"down"},300);
            setTimeout('Omplus.globals.getObject("' + this.omplusName + '").remove("#' + this.omplusName + "_" + this.index + '")', 3000);
            this.index++;
        }
    },
    remove:function (id) {
        $(id).fadeOut(300, function () {
            $(this).remove();
        });
    }
});